package game;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class InputGame {
	private Game game;
	public String gameDesc = "";

private String filename;
public InputGame(String s) throws FileNotFoundException{
 
	this.filename = s;
	this.game = gameCreator();
}
public InputGame(){
	
}



	public Game getGame() {
	return game;
}
	public Game gameCreator() throws FileNotFoundException {
			Scanner in = new Scanner(System.in);
			
			File file1 = new File(filename);
			in = new Scanner(file1);

		//	System.out.println("OK!");
			
			String s1 = in.nextLine();
			String gameName = s1;
			this.gameDesc = this.gameDesc+s1+"\n\r";

			
			s1 = in.nextLine();
			this.gameDesc = this.gameDesc+s1+"\n\r";
			int size = Integer.parseInt(s1);

			int end = 0;
			int numOfCages = 0;

			String[] cages = new String[size*size];

			while (in.hasNext() && !(end == 1)) {
				s1 = in.nextLine();
				this.gameDesc = this.gameDesc+s1+"\n\r";
				if (s1.equals("end " + gameName)) {
					end = 1;
					break;
				} else {
					cages[numOfCages] = s1;
					numOfCages++;
				}
			}
			
			Game game = new Game(size);

			for (int i = 0; i < numOfCages; i++) {
				String[] formula = cages[i].split(" ");
				game.addCage(formula);
			}
		//	System.out.println(game.mCells);
			return game;
			
		
	}
	
}
